微信小程序获取屏幕高度宽度
微信小程序获取屏幕高度方法一:
onLoad:function(){
this.setData({
height:wx.getSystemInfoSync().windowHeight,
width:wx.getSystemInfoSync().windowWidth
})
}
微信小程序获取屏幕高度方法二:
.index{
height:100vh;
width:100vw;
}
#CSS3引入的"vw"和"vh"基于宽度/高度相对于窗口大小
#"vw"="viewwidth""vh"="viewheight"
微信小程序获取屏幕高度 小程序屏幕高度怎么获取
微信小程序获取屏幕高度方法三:
letthat=this;
//获取系统信息
wx.getSystemInfo({
success:function(res){
//获取可使用窗口宽度
letclientHeight=res.windowHeight;
//获取可使用窗口高度
letclientWidth=res.windowWidth;
//算出比例
letratio=750/clientWidth;
//算出高度(单位rpx)
letheight=clientHeight*ratio;
//设置高度
that.setData({
height:height
});
}
});
方法四:获取微信小程序内元素高度
constquery=wx.createSelectorQuery()//定义query
query.select('#txt_medium').boundingClientRect()//获取元素参数
query.exec((res)=>{
console.log(res)//可以得到元素高度、距离顶部的top值、宽度等,单位为px
})
方法五:获取微信小程序屏幕高度和宽度,单位:px
height:wx.getSystemInfoSync().windowHeight,
width:wx.getSystemInfoSync().windowWidth